package org.ccay.core.util;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;
/**
 * 判断url连接是否有效
 * 
 *
 */
public class SocketUtil {
	
	private SocketUtil(){}
	
	public static boolean checkConnection(String url){
		HttpMethod methodObj = null;
		try{
			methodObj = new GetMethod(url);
			HttpClient client = new HttpClient();
			int statusCode = client.executeMethod(methodObj); 
			if(HttpUtil.isNormalResponse(statusCode)){
				return true;
			}
		} catch (Exception e) {
			return false;
		} finally{
			if(null != methodObj){
				methodObj.releaseConnection();
			}
		}
		return false;
	}

}
